<!DOCTYPE html>
<html>
<head>
<title>Physics Diagram Fig 2.84</title>
</head>
<body>

<canvas id="physicsCanvas" width="600" height="400" style="border: none;"></canvas>

<script>
const canvas = document.getElementById('physicsCanvas');
const ctx = canvas.getContext('2d');

// --- Style Settings ---
ctx.strokeStyle = 'black';
ctx.fillStyle = 'black';
ctx.lineWidth = 2.5;
ctx.lineCap = 'round';
ctx.lineJoin = 'round';

// --- Draw Light Source (Square) ---
// A simple square box on the left.
ctx.strokeRect(50, 145, 100, 100);

// --- Common Y coordinate for horizontal alignment ---
const midY = 195;

// --- Draw Light Beam ---
const beamStartX = 150; // Right edge of the source box
const wavyEndX = 250;
const arrowTipX = 340;

// Label 'light'
ctx.save();
// Using a font that resembles the handwritten style in the image.
ctx.font = '24px "Comic Sans MS", cursive, sans-serif';
ctx.textAlign = 'center';
ctx.fillText('light', (beamStartX + wavyEndX) / 2 + 10, midY - 35);
ctx.restore();

// Wavy part (zigzag representation)
ctx.beginPath();
ctx.moveTo(beamStartX, midY);
let x = beamStartX;
const numWiggles = 4;
const amplitude = 8;
// Each wiggle is an up-down movement, so we need 2*numWiggles segments
const segmentLength = (wavyEndX - beamStartX) / (numWiggles * 2);
for (let i = 0; i < numWiggles; i++) {
    ctx.lineTo(x + segmentLength, midY - amplitude);
    ctx.lineTo(x + 2 * segmentLength, midY);
    x += 2 * segmentLength;
}
// Straight part
ctx.lineTo(arrowTipX, midY);
ctx.stroke();

// Arrowhead
ctx.beginPath();
ctx.moveTo(arrowTipX, midY);
ctx.lineTo(arrowTipX - 15, midY - 8);
ctx.moveTo(arrowTipX, midY);
ctx.lineTo(arrowTipX - 15, midY + 8);
ctx.stroke();


// --- Draw Target and Axle ---
const targetCenterX = 410;
const targetRadiusX = 40;
const targetRadiusY = 60;
const axleStartX = targetCenterX - targetRadiusX;
const axleEndX = 530;

// Axle line (drawn through the target area)
ctx.beginPath();
ctx.moveTo(axleStartX, midY);
ctx.lineTo(axleEndX, midY);
ctx.stroke();

// Target (Ellipse), drawn over the axle line
ctx.beginPath();
ctx.ellipse(targetCenterX, midY, targetRadiusX, targetRadiusY, 0, 0, 2 * Math.PI);
ctx.stroke();

// --- Draw Labels for Target and Axle ---
ctx.save();
ctx.font = '24px "Comic Sans MS", cursive, sans-serif';
ctx.textAlign = 'center';

// Label 'target'
ctx.fillText('target', targetCenterX, midY + targetRadiusY + 30);

// Label 'axle'
ctx.textAlign = 'left';
ctx.fillText('axle', axleEndX + 10, midY + 5);
ctx.restore();


// --- Draw Figure Caption ---
ctx.save();
// Using a bold serif font for the caption as in the original.
ctx.font = 'bold 24px "Times New Roman", serif';
ctx.textAlign = 'center';
ctx.fillText('Fig. 2.84', canvas.width / 2, 360);
ctx.restore();

</script>

</body>
</html>